package org.iteam.xlz.manager.action.base;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.iteam.web.shiro.ShiroUtil;
import org.iteam.web.struts.action.AbstractModuleAction;
import org.iteam.web.struts.action.RestAction;
import org.iteam.xlz.core.entity.ticket.TicketType;
import org.iteam.xlz.core.service.base.TickettypeService;

@SuppressWarnings("unchecked")
@Results({@Result(name="INDEX",type="freemarker",location="/WEB-INF/content/base/tickettype/index.html"),
	  @Result(name="EDIT",type="freemarker",location="/WEB-INF/content/base/tickettype/edit.html")})
public class TicketTypeAction extends AbstractModuleAction<TicketType> implements RestAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = 7043319468046542252L;
	private final String PATH="/base/tickettype";	
	private final String NODEPATH="/base/ticketnodetype";
	@Override
	public TicketType getModel() {
		if(null==model){
			model=new TicketType();
		}
		return model;
	}

	@Override
	@Actions({@Action(PATH+"/index"),@Action(NODEPATH+"/{_parent}/index")})
	public String index(){
		return INDEX;		
	}


	@Override
	@Actions({@Action(PATH+"/query"),@Action(NODEPATH+"/{_parent}/query")})
	public String query() {
		map.put("total",TickettypeService.getInstance().counts(_parent));
		map.put("rows",TickettypeService.getInstance().query(_parent,page,rows));
		return MAP;
	}

	@Override
	@Actions({@Action(PATH+"/create"),@Action(NODEPATH+"/{_parent}/create")})
	public String create() {
		model.setCreator(ShiroUtil.currentAccount());
		map.put("state",TickettypeService.getInstance().create(model));
		return MAP;
	}

	@Override
	@Actions({@Action(PATH+"/update"),@Action(NODEPATH+"/{_parent}/update")})
	public String update() {
		map.put("state",TickettypeService.getInstance().update(model));
		return MAP;
	}

	@Override
	@Actions({@Action(PATH+"/{_id}/delete"),@Action(NODEPATH+"/{_parent}/{_id}/delete")})
	public String delete() {
		map.put("state",TickettypeService.getInstance().delete(_id));
		return MAP;
	}

	@Override
	public String destroy() {
		return null;
	}

	@Override
	@Actions({@Action(PATH+"/{_id}/edit"),@Action(NODEPATH+"/{_parent}/{_id}/edit")})
	public String edit() {
		super.object=TickettypeService.getInstance().findById(_id);
		return EDIT;
	}

	@Override
	@Actions({@Action(PATH+"/new"),@Action(NODEPATH+"/{_parent}/new")})
	public String editNew() {
		return EDIT;
	}

	@Override
	public String show() {
		return null;
	}

}
